//app.js
var CryptoJS = require('utils/crypto-js/crypto-js.min.js');
App({
  onLaunch: function() {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    wx.getSystemInfo({
      success: res => {
        let statusBarHeight = res.statusBarHeight,
          navTop = menuButtonObject.top,//胶囊按钮与顶部的距离
          navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight)*2;//导航高度
        this.globalData.navHeight = navHeight;
        this.globalData.navTop = navTop;
        this.globalData.windowHeight = res.windowHeight;
      },
      fail(err) {
        console.log(err);
      }
    })
  },
  ecbEncrypto: function (content) {
    var key = CryptoJS.enc.Utf8.parse('1234567812345678')//base64编码
    var srcs = CryptoJS.enc.Utf8.parse(JSON.stringify(content))//base64编码
    var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
    return encrypted.toString()
  },
  ecbDecrypto: function (cryptoContent) {
    var key = CryptoJS.enc.Utf8.parse('1234567812345678')
    var decrypt = CryptoJS.AES.decrypt(cryptoContent, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
    return CryptoJS.enc.Utf8.stringify(decrypt).toString()
  },
  globalData: {
    flag:false,
  },
  reduceTime(time1,time2){
    var time1=new Date(time1.replace(/-/g,"/"));
    var time2=new Date(time2.replace(/-/g,"/"));

    var times=time1.getTime()-time2.getTime();//时间差的毫秒数

    var days=parseInt(times/(24*1000*3600));//计算相差的天数
    var leave=times%(24*3600*1000);//计算天数后剩余的毫秒数

    var h=parseInt(leave/(3600*1000));//计算小时数

     //计算分钟数
    var h_leave=leave%(3600*1000);
    var min=parseInt(h_leave/(60*1000));

     //计算秒数
    var min_leave=h_leave%(60*1000);
    var sec=parseInt(min_leave/1000);
    return `${days?(days + '天'):''}${h?(h + '时'):''}${min?(min + '分'):''}`
  },
  shopId : "",
  colorName : "orange",
  userInfo: {},
  shopInfo: {},
  goodTypes:[],
  memberId: "",
  goodsTypeFilter: "",
  goodsListFilter: "",
  gpid: "",
  userName: '',
  nickname: '',
  //测试
  url: "https://www.xingyuwulian.com/smartLight",
  imageUrl: "https://www.xingyuwulian.com/file/"

  //广州项目
  // url: "https://www.huadulds.com/smartLight",
  // imageUrl: "https://www.huadulds.com/file/"
})
